import pytest
from common import log,mail,consts,shell
from config import config
from common.tools import zip_dir
import os


if __name__ == '__main__':
    from common.tools import create_case
    create_case()
    conf = config.Config()
    log = log.Log.get_logger()
    log.info('初始化配置文件，path='+conf.log_path)

    shell = shell.Shell()
    xml_reprot_path = consts.XML_REPORT_PATH
    html_report_path = consts.HTML_REPORT_PATH
    cases_path = consts.CASE_PATH
    attach_file = os.path.join(consts.DATA_PATH,'report.zip')

    args = ['-s','-q','--alluredir',xml_reprot_path,cases_path,'--clean-alluredir']
    pytest.main(args)

    cmd = 'allure generate -c {} -o {}'.format(xml_reprot_path,html_report_path)

    zip_dir(consts.REPORT_PATH,attach_file)

    shell.execute(cmd)
    mail = mail.send_email(attach_file)